package com.cupcorn.lib.game;

import java.io.IOException;

import org.andengine.audio.sound.Sound;
import org.andengine.audio.sound.SoundFactory;

import com.cupcorn.lib.define.GameEngineConfiguration;
import com.cupcorn.lib.game.element.GameElementMusic;

public class GameSound
{
	Sound	sfx;
	boolean	paused;
	
	public GameSound(GameEngine engine, GameElementMusic gameElementMusic) throws IOException
	{
		paused = false;
		
		sfx = SoundFactory.createSoundFromAsset(engine.getSoundManager(), engine, gameElementMusic.path);
		sfx.setLooping(gameElementMusic.looping);
	}
	
	public void play()
	{
		if (!GameEngineConfiguration.use_sound) return;
		paused = false;
		sfx.play();
	}
	
	public void pause()
	{
		if (!GameEngineConfiguration.use_sound) return;
		paused = true;
		sfx.pause();
	}
	
	public void resume()
	{
		if (!GameEngineConfiguration.use_sound) return;
		if (paused)
		{
			paused = false;
			sfx.play();
		}
		else
		{
			System.out.println("cannot resume sound...");
		}
	}
}
